/*
 * Copyright (C) 2014 VenomVendor <info@VenomVendor.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.bocai.dahuatech.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.PointListBean;
import com.bocai.dahuatech.R;

import java.util.List;

public class MyPointAdapterHolder extends RecyclerView.Adapter<MyPointAdapterHolder.ViewHolder> {

    OnItemClickListener mItemClickListener;
    List<PointListBean.ContentEntity> datas;
    public MyPointAdapterHolder(Context context, List<PointListBean.ContentEntity> datas) {
        this.datas=datas;
    }
    public void addDatas(List<PointListBean.ContentEntity> list){
        datas.addAll(list);
        this.notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final LayoutInflater mInflater = LayoutInflater.from(parent.getContext());
        final View sView = mInflater.inflate(R.layout.my_point_item, parent, false);
        return new ViewHolder(sView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvTime.setText(datas.get(position).getFDate());
        holder.tvNumber.setText(datas.get(position).getFBillNo());
        holder.tvCount.setText(datas.get(position).getFCoin()+"");
        holder.tvState.setText(datas.get(position).getFStatus());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void SetOnItemClickListener(final OnItemClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        TextView tvTime,tvNumber,tvCount,tvState;
        public ViewHolder(View view) {
            super(view);
            tvTime= (TextView) view.findViewById(R.id.tv_pointlist_time);
            tvNumber= (TextView) view.findViewById(R.id.tv_pointlist_number);
            tvCount= (TextView) view.findViewById(R.id.tv_pointlist_count);
            tvState= (TextView) view.findViewById(R.id.tv_pointlist_state);
            view.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mItemClickListener != null) {
//                mItemClickListener.onItemClick(v, getPosition());
                mItemClickListener.onItemClick(v, getLayoutPosition());
            }
        }

    }

}
